package com.yanzhang.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author yanzhang
 */
public class DateUtil {

    public enum Time_Zone {
       SYSTEM, GMT
    }

    public final static String format = "yyyy-MM-dd";

    public static DateFormat date_format;

    static {
        date_format = new SimpleDateFormat(format);
    }

    public static Date getDate (String str,Time_Zone time_zone) {
        try {
            Date parse = date_format.parse(str);
            Date time = null;
            switch (time_zone) {
                case SYSTEM: {
                    time = new Date(parse.getTime());
                    break;
                }
                case GMT: {
                    time = new Date(parse.getTime() + 8 * 60 * 60 * 1000);
                    break;
                }
                default: {

                    break;
                }
            }
            return time;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}
